{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import datetime"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "data=pd.read_table('E:\\\\pythoncoding\\\\data\\\\bank-saw.txt',header=None,delim_whitespace=True)\n",
    "data.to_csv('E:\\\\pythoncoding\\\\data\\\\bank-saw.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "       code  name  price   bvps    pb2 shouyi7 fanbei7\n",
      "0        代码  股票名称     价格  今日净资产   市净率2     收益7     翻倍7\n",
      "1  HK003328  交通银行  3.946  7.146  0.552   0.132  0.8023\n",
      "2  HK000998  中信银行  3.845   6.68  0.576   0.174  0.8764\n",
      "3  HK003618  重庆农商  3.214   5.23  0.615   0.184  1.2208\n",
      "4  HK006818  光大银行  2.768  4.477  0.618   0.169  1.3565\n",
      "             code   name   price    bvps    pb2 shouyi7 fanbei7\n",
      "1        HK003328   交通银行   3.946   7.146  0.552   0.132  0.8023\n",
      "2        HK000998   中信银行   3.845    6.68  0.576   0.174  0.8764\n",
      "3        HK003618   重庆农商   3.214    5.23  0.615   0.184  1.2208\n",
      "4        HK006818   光大银行   2.768   4.477  0.618   0.169  1.3565\n",
      "5        HK001288   农业银行   2.272   3.543  0.641   0.158  1.6977\n",
      "6        HK003988   中国银行   2.574   4.125  0.624   0.136  1.7363\n",
      "7        HK000939   建设银行   3.979   5.816  0.684    0.18  1.8971\n",
      "8        HK001988   民生银行    5.67   8.486  0.668   0.162  1.9305\n",
      "9        HK001398   工商银行   3.399   4.924   0.69    0.18  1.9519\n",
      "10       SH601939   建设银行    4.71   5.816   0.81    0.18  2.9166\n",
      "11       SH601818   光大银行    3.55   4.477  0.793   0.169  2.9462\n",
      "12       HK003968   招商银行  13.293  14.915  0.891   0.207  3.0692\n",
      "13       SH601398   工商银行    4.13   4.924  0.839    0.18  3.1309\n",
      "14       SH601166   兴业银行   14.74  15.686   0.94   0.216  3.2274\n",
      "15       SH601328   交通银行    5.33   7.146  0.746   0.132  3.2326\n",
      "16       SH601998   中信银行    5.65    6.68  0.846   0.174  3.2745\n",
      "17       SH600015   华夏银行    9.79  11.272  0.869   0.178  3.3758\n",
      "18       SH601009   南京银行   15.63  14.427  1.083    0.25  3.4604\n",
      "19       SH601988   中国银行    3.28   4.125  0.795   0.136  3.6332\n",
      "20       SH600036   招商银行   15.15  14.915  1.016   0.207  3.7637\n",
      "21       SH601288   农业银行    3.08   3.543  0.869   0.158  3.7779\n",
      "22       SH601169   北京银行    9.95   9.219  1.079   0.219  3.8895\n",
      "23       SH600000   浦发银行   18.45  15.761  1.171   0.242  3.9258\n",
      "24       SZ002142   宁波银行   12.93  10.668  1.212   0.242  4.0914\n",
      "25       SZ000001   平安银行   10.11  11.635  0.869   0.145  4.0927\n",
      "26       SH600016   民生银行     8.7   8.486  1.025   0.162  4.7806\n",
      "27       2016/3/3  17:33       4     条评论    NaN     NaN     NaN\n",
      "29       HK000998   中信银行   3.891   6.683  0.582   0.174  0.9475\n",
      "30       HK003328   交通银行   4.033   7.149  0.564   0.132  0.9767\n",
      "31       HK003618   重庆农商   3.294   5.232   0.63   0.184  1.3636\n",
      "...           ...    ...     ...     ...    ...     ...     ...\n",
      "11580    SH601009   南京银行    7.97    6.74   1.18    0.12     7.6\n",
      "11581    SZ002142   宁波银行    17.3    9.76   1.77    0.14     9.6\n",
      "11582  2017/10/27  17:59       1     条评论    NaN     NaN     NaN\n",
      "11584    HK006818   光大银行   3.154    5.22    0.6    0.13     1.6\n",
      "11585    HK000998   中信银行   4.313    7.41   0.58     0.1     1.7\n",
      "11586    HK001988   民生银行   6.384   10.05   0.64    0.15     1.8\n",
      "11587    HK003328   交通银行   5.089    8.13   0.63    0.11     2.1\n",
      "11588    HK003618   重庆农商   4.424    6.27   0.71    0.17     2.2\n",
      "11589    HK001963   重庆银行   5.413    8.39   0.65    0.11     2.4\n",
      "11590    HK003988   中国银行   3.444    4.78   0.72    0.12     3.3\n",
      "11591    HK001288   农业银行   3.103    4.12   0.75    0.13     3.5\n",
      "11592    SH600016   民生银行    8.17   10.05   0.81    0.15     3.6\n",
      "11593    SH601818   光大银行    4.05    5.22   0.78    0.13     3.7\n",
      "11594    SH600015   华夏银行    9.34   11.46   0.81    0.14     3.8\n",
      "11595    SH601328   交通银行    6.26    8.13   0.77    0.11       4\n",
      "11596    HK000939   建设银行    5.89    6.77   0.87    0.14     4.1\n",
      "11597    HK001398   工商银行   5.353    5.75   0.93    0.14     4.7\n",
      "11598    SH601988   中国银行    4.05    4.78   0.85    0.12     4.8\n",
      "11599    SH601166   兴业银行   17.66   18.59   0.95    0.14     4.8\n",
      "11600    SH601288   农业银行    3.74    4.12   0.91    0.13       5\n",
      "11601    SH601939   建设银行    7.25    6.77   1.07    0.14     5.7\n",
      "11602    SH601998   中信银行    6.22    7.41   0.84     0.1     5.7\n",
      "11603    SH601398   工商银行    6.25    5.75   1.09    0.14     5.9\n",
      "11604    HK003968   招商银行    25.7   17.61   1.46     0.2     5.9\n",
      "11605    SZ000001   平安银行   11.56   11.63   0.99    0.12       6\n",
      "11606    SH600036   招商银行   27.79   17.61   1.58     0.2     6.4\n",
      "11607    SH601169   北京银行     7.4    7.49   0.99     0.1     7.5\n",
      "11608    SH601009   南京银行    8.02    6.69    1.2    0.12     7.9\n",
      "11609    SZ002142   宁波银行   17.34    9.77   1.77    0.14     9.6\n",
      "11610  2017/10/30  16:31     NaN     NaN    NaN     NaN     NaN\n",
      "\n",
      "[11311 rows x 7 columns]\n"
     ]
    }
   ],
   "source": [
    "bankdata=pd.read_csv('E:\\\\pythoncoding\\\\data\\\\bank-saw.csv',header=None,names=[\"code\",\"name\",\"price\",\"bvps\",\"pb2\",\"shouyi7\",\"fanbei7\"],encoding=\"gbk\")\n",
    "\n",
    "print bankdata.head(5)\n",
    "def processcharactor(x):\n",
    "    if x==u\"代码\" or x==u\"股票名称\" or x==u\"价格\" or x==u\"今日净资产\" or x==u\"市净率2\" or x==u\"收益7\" or x==u\"翻倍7\":\n",
    "        x=\"NA\"\n",
    "    else:\n",
    "        return x\n",
    "\n",
    "        \n",
    "bankdata=bankdata.applymap(processcharactor)\n",
    "bankdata=bankdata.dropna(how=\"all\")\n",
    "bankdata"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "u'\\u4ee3\\u7801'"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bankdata.iloc[0,0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "==\n"
     ]
    }
   ],
   "source": [
    "if u\"代码\"==u'\\u4ee3\\u7801':\n",
    "    print \"==\"\n",
    "else:\n",
    "    print \"!=\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "\n",
    "bankdata.to_csv('E:\\\\pythoncoding\\\\data\\\\bankdata.csv',encoding=\"gbk\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "       code      name  price   bvps    pb2 shouyi7 fanbei7\n",
      "0  HK003328   ��ͨ����  3.946  7.146  0.552   0.132  0.8023\n",
      "1  HK000998  ��������  3.845   6.68  0.576   0.174  0.8764\n",
      "2  HK003618   ����ũ��  3.214   5.23  0.615   0.184  1.2208\n",
      "3  HK006818   �������  2.768  4.477  0.618   0.169  1.3565\n",
      "4  HK001288    ũҵ����  2.272  3.543  0.641   0.158  1.6977\n"
     ]
    }
   ],
   "source": [
    "bankdata=pd.read_csv('E:\\\\pythoncoding\\\\data\\\\bankdata.csv',encoding=\"gbk\",)\n",
    "print bankdata.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python [conda root]",
   "language": "python",
   "name": "conda-root-py"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
